package com.ymm.system.controller;

import com.ymm.driver.api.constants.Entity.DriverEntity;
import com.ymm.lulutong.dto.OrderShipperDTO;

import com.ymm.system.api.constants.CargoEntity;
import com.ymm.system.api.dto.*;
import com.ymm.system.api.facade.*;
import com.ymm.system.api.utils.Result;
//import com.ymm.system.core.config.mq.Producer;
import com.ymm.system.core.repo.DriverRelatedRepo;
import com.ymm.system.core.repo.ShipperRelatedRepo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Company: CUG
 * @Description: TODO
 * @Author: LiYangyong
 * @Date: 2022/8/1/001 23:07
 **/


@Slf4j
@RestController
@RequestMapping("/system")
public class SystemController {


//    @Autowired
//    private Producer producer;

    @Autowired
    private SystemDefinePriceService systemPriceService;

    @Autowired
    private SystemDisplayService systemDisplayService;

    @Autowired
    private SystemDriverOrderTradeService systemDriverOrderTradeService;

    @Autowired
    private SystemShipperOrderService systemShipperOrderService;

    @Autowired
    private ShipperRelatedRepo shipperRelatedRepo;

    @Autowired
    private DriverRelatedRepo driverRelatedRepo;

    @Autowired
    private SystemGenerateOrderTradeService systemGenerateOrderTradeService;

    @Autowired
    private SystemMatchService systemMatchService;

    @RequestMapping("/price")
    public Integer definePriceTest(){
        CargoPriceRequest cargoPriceRequest = new CargoPriceRequest();
        cargoPriceRequest .setCargoDesLat(BigDecimal.valueOf(118.7787));
        cargoPriceRequest .setCargoDesLon(BigDecimal.valueOf(31.99226));
        cargoPriceRequest .setCargoSrcLat(BigDecimal.valueOf(118.798));
        cargoPriceRequest .setCargoSrcLon(BigDecimal.valueOf(32.04835));
        cargoPriceRequest .setCargoDeliveryTime(new Date(2022,10,1,11,23,11));
        cargoPriceRequest .setCargoRequireType(2);
        cargoPriceRequest.setCity("北京市");
        return systemPriceService.definePrice(cargoPriceRequest).getData();
    }

//    @PostMapping("/testPushMessage")
//    public Result<Boolean> test23(Long orderId){
//        Result<Boolean> booleanResult = systemShipperOrderService.confirmReceipt(orderId);
//        return booleanResult;
//    }


    @RequestMapping("/testTrade")
    private String testTradeState(Long tradeId){
        log.info("tradeId:{}",tradeId);
        Result result = systemDriverOrderTradeService.updateTradeState(tradeId);
        return result.getCode().toString();
    }


    @RequestMapping("/testBatchShipper")
    public com.ymm.lulutong.utils.Result<List<OrderShipperDTO>> test999(){
        List<Long> ShipperIds = new ArrayList<>();
        ShipperIds.add(1L);
        ShipperIds.add(2L);
        com.ymm.lulutong.utils.Result<List<OrderShipperDTO>> shipperInfo =
                shipperRelatedRepo.batchGetShipperInfo(ShipperIds);
        return shipperInfo;
    }

    @RequestMapping("/testShipper")
    public com.ymm.lulutong.utils.Result<OrderShipperDTO> test888(){
        return shipperRelatedRepo.getShipperInfo(1L);

    }

    @RequestMapping("/testDriver")
    public com.ymm.driver.api.utils.Result<DriverEntity> test2(){
        BigInteger bigInteger = new BigInteger("1");
        return driverRelatedRepo.getDriverInfo(bigInteger);
    }

    @RequestMapping("/testDrivers")
    public com.ymm.driver.api.utils.Result<List<DriverEntity>> test3(){
        ArrayList<BigInteger> list=new ArrayList<>();
        BigInteger bigInteger = new BigInteger("1");
        BigInteger bigInteger1 = new BigInteger("2");
        list.add(bigInteger);
        list.add(bigInteger1);
        return driverRelatedRepo.batchGetDriverInfo(list);
    }


    @RequestMapping("/testOrder")
    public OrderShowDTO test(){
        List<OrderShowDTO> orderShowDTOList = systemDisplayService.searchOrderDetailsByPage(1,3);
        return orderShowDTOList.get(0);
    }


//        @GetMapping(value = "/test")
//        public Object test(String msg) {
//            String str = "Hello World,My First RocketMQ Message=" + msg;
//            producer.sendMessage("testTopic",str);
//            System.out.println("生产者启动......");
//            return "success";
//        }

//        @GetMapping("/testAddPrice")
//        public Result<Boolean> test11(Long orderId){
//            Result<Boolean> booleanResult = systemShipperOrderService.confirmReceipt(orderId);
//            return booleanResult;
//        }

        @GetMapping("/get")
        public com.ymm.lulutong.utils.Result<OrderShipperDTO> getShipperDto(Long shipperId){
            return shipperRelatedRepo.getShipperInfo(shipperId);
        }

        @RequestMapping("/isAllowedGrab")
        public Result test1111(){
            DriverGrabDTO driverGrabDTO = new DriverGrabDTO();
            driverGrabDTO.setDriverId(1L);
            driverGrabDTO.setCargoId(85L);
            driverGrabDTO.setDriverLocation("南京市雨花台区软件大道");
            Result result = systemGenerateOrderTradeService.generateOrder(driverGrabDTO);
            return result;
        }

        @RequestMapping("/gotoGrab")
        public Result<CargoInfoDto> test223(){
            DriverGrabDTO driverGrabDTO = new DriverGrabDTO();
            driverGrabDTO.setDriverId(4L);
            driverGrabDTO.setCargoId(88L);
            driverGrabDTO.setDriverLocation("南京");
            Result<CargoInfoDto> cargoInfoDtoResult =
                    systemDisplayService.driverSearchCargoDetails(driverGrabDTO);
            return cargoInfoDtoResult;
        }

        @RequestMapping("/testDayCargo")
        public Result<List<CargoDTO>> test333(){
            Double driverLat=31.92;
            Double driverLon=118.75;
            Integer driverCartype=4;
            Result<List<CargoDTO>> listResult =
                    systemMatchService.driverSearchDayCargoService(driverLat, driverLon, driverCartype);
            return listResult;
        }

    @RequestMapping("/testpushcargo")
    public Result<List<CargoDTO>> test444(){
        return systemMatchService.PushLongTimeCargo(31.99, 118.78, 2, 1L);
    }
}
